package top.purity.framework.common.result;

import lombok.AllArgsConstructor;
import lombok.Data;

/**
 * @version 1.0
 * @Author Lmh
 * @Description
 * @CreateTime 2023-09-20 20:00
 */

@Data
@AllArgsConstructor
public class RespResult {

    private Integer code;

    private String msg;

    private Object data;

    public RespResult(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public RespResult(String msg) {
        this.msg = msg;
    }

    public static RespResult ok(Object data) {
        return new RespResult(GlobalRespCode.SUCCESS.getCode(), GlobalRespCode.SUCCESS.getMsg(), data);
    }

    public static RespResult ok() {
        return new RespResult(GlobalRespCode.SUCCESS.getCode(), GlobalRespCode.SUCCESS.getMsg());
    }

    public static RespResult ok(GlobalRespCode code) {
        return new RespResult(code.getCode(), code.getMsg());
    }

    public static RespResult error(GlobalRespCode code) {
        return new RespResult(code.getCode(), code.getMsg());
    }

    public static RespResult error(String msg) {
        return new RespResult(GlobalRespCode.ERROR.getCode(), msg);
    }

    public static RespResult error(String msg, Integer code) {
        return new RespResult(code, msg);
    }
}
